<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>bfsNet: Fichero Fuente /Users/nicolunacba/Development/Dinic/trunk/network/network.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generado por Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Buscar');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="bfs-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">bfsNet&#160;<span id="projectnumber">1.0</span></div>
   <div id="projectbrief">Algoritmo BFS para encontrar un camino de fuente a destino en una Network</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Página&#160;principal</span></a></li>
      <li><a href="annotated.html"><span>Estructuras&#160;de&#160;Datos</span></a></li>
      <li class="current"><a href="files.html"><span>Archivos</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Buscar" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Lista&#160;de&#160;archivos</span></a></li>
      <li><a href="globals.html"><span>Globales</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('network_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">/Users/nicolunacba/Development/Dinic/trunk/network/network.c</div>  </div>
</div>
<div class="contents">
<a href="network_8c.html">Ir a la documentación de este archivo.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &quot;<a class="code" href="network_8h.html">network.h</a>&quot;</span>
<a name="l00004"></a>00004 
<a name="l00006"></a><a class="code" href="structs_network.html">00006</a> <span class="keyword">struct </span><a class="code" href="structs_network.html">sNetwork</a>
<a name="l00007"></a>00007 {
<a name="l00011"></a><a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">00011</a>     <a class="code" href="structhashtbl.html">HASHTBL</a> * <a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a>; 
<a name="l00013"></a><a class="code" href="structs_network.html#a115584eca6ba1b29ea2428af2d665358">00013</a>     <span class="keywordtype">int</span> <a class="code" href="structs_network.html#a115584eca6ba1b29ea2428af2d665358">NetSize</a>;
<a name="l00014"></a>00014 };
<a name="l00015"></a>00015 
<a name="l00017"></a><a class="code" href="network_8h.html#af0a594ae08f23dbd93ff68c2f4e72f98">00017</a> <a class="code" href="structs_network.html">Network</a> <a class="code" href="network_8c.html#af0a594ae08f23dbd93ff68c2f4e72f98">network_create</a> (<span class="keywordtype">void</span>)
<a name="l00018"></a>00018 {
<a name="l00019"></a>00019     <a class="code" href="structs_network.html">Network</a> NewNet = NULL;
<a name="l00020"></a>00020     
<a name="l00021"></a>00021     NewNet = (<a class="code" href="network_8h.html#a78f5e3805d6401ebba27a8a03041a3f8">Network</a>) malloc (<span class="keyword">sizeof</span> (<span class="keyword">struct</span> <a class="code" href="structs_network.html">sNetwork</a>));
<a name="l00022"></a>00022     <span class="keywordflow">if</span>(NewNet != NULL){
<a name="l00023"></a>00023         NewNet-&gt;<a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a> = <a class="code" href="hashtbl_8c.html#aa7e342f8612905f6d59e444d82b52954">hashtbl_create</a> (1, NULL); <span class="comment">/* Hay que verificar esto */</span>
<a name="l00024"></a>00024         NewNet-&gt;<a class="code" href="structs_network.html#a115584eca6ba1b29ea2428af2d665358">NetSize</a> = 0;
<a name="l00025"></a>00025     }
<a name="l00026"></a>00026     
<a name="l00027"></a>00027     <span class="keywordflow">return</span> NewNet;
<a name="l00028"></a>00028 }
<a name="l00029"></a>00029 
<a name="l00031"></a><a class="code" href="network_8h.html#a2e032cd8fed30af6eacbaead8408c126">00031</a> <span class="keywordtype">void</span> <a class="code" href="network_8c.html#a2e032cd8fed30af6eacbaead8408c126">network_add_node</a> (<a class="code" href="structs_network.html">Network</a> net, <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> NodeSource, <a class="code" href="structs_tuple.html">Node_tuple</a> NodeTup)
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033         <a class="code" href="structs_list.html">List</a> neigh_list;
<a name="l00034"></a>00034         <span class="keywordtype">int</span> error;
<a name="l00035"></a>00035         <span class="keywordflow">if</span> (<a class="code" href="hashtbl_8c.html#a09a188d83a55ba59116a7c301c032a68">hashtbl_get</a> (net-&gt;<a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a>, (<span class="keyword">const</span> <span class="keywordtype">char</span> *) &amp;NodeSource) == NULL)
<a name="l00036"></a>00036         {
<a name="l00037"></a>00037                 neigh_list = <a class="code" href="list_8c.html#a92bbfe84653d1fedb6e463414d7bb109">list_create</a>();
<a name="l00038"></a>00038                 neigh_list = <a class="code" href="list_8c.html#a563fa4772b82dd3c2c0f4927bcfcff8a">list_add_new_elem</a>(neigh_list, NodeTup);
<a name="l00039"></a>00039                 net-&gt;<a class="code" href="structs_network.html#a115584eca6ba1b29ea2428af2d665358">NetSize</a>++;
<a name="l00040"></a>00040                 error = <a class="code" href="hashtbl_8c.html#a460651cb9ee95096d0a37ad691b8966c">hashtbl_resize</a>(net-&gt;<a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a>, net-&gt;<a class="code" href="structs_network.html#a115584eca6ba1b29ea2428af2d665358">NetSize</a>); 
<a name="l00041"></a>00041                 error = <a class="code" href="hashtbl_8c.html#a6b2853739dee3d59dcca062d62ac4600">hashtbl_insert</a>(net-&gt;<a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a>, (<span class="keyword">const</span> <span class="keywordtype">char</span> *) &amp;NodeSource, neigh_list);              
<a name="l00042"></a>00042         }
<a name="l00043"></a>00043         <span class="keywordflow">else</span>
<a name="l00044"></a>00044         {
<a name="l00045"></a>00045                 neigh_list = <a class="code" href="hashtbl_8c.html#a09a188d83a55ba59116a7c301c032a68">hashtbl_get</a> (net-&gt;<a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a>, (<span class="keyword">const</span> <span class="keywordtype">char</span> *) &amp;NodeSource);
<a name="l00046"></a>00046                 <span class="keywordflow">if</span> (!<a class="code" href="list_8c.html#a9488cf0bffafdf9a10b591b465b47743">list_exists_elem</a>(neigh_list, NodeTup))
<a name="l00047"></a>00047                 {
<a name="l00048"></a>00048                         neigh_list = <a class="code" href="list_8c.html#a563fa4772b82dd3c2c0f4927bcfcff8a">list_add_new_elem</a>(neigh_list, NodeTup);
<a name="l00049"></a>00049                 }
<a name="l00050"></a>00050         }
<a name="l00051"></a>00051 }
<a name="l00052"></a>00052 
<a name="l00054"></a><a class="code" href="network_8h.html#a7284c2b25118f29553d6ce6262f95a54">00054</a> <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a>* <a class="code" href="network_8c.html#a7284c2b25118f29553d6ce6262f95a54">network_get_neighbours</a> (<a class="code" href="structs_network.html">Network</a> net, <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> NodeSource)
<a name="l00055"></a>00055 {
<a name="l00056"></a>00056         <a class="code" href="structs_list.html">List</a> neigh_node;
<a name="l00057"></a>00057         <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> *array_fromlist = NULL;
<a name="l00058"></a>00058         <a class="code" href="structs_tuple.html">Tuple</a> NodeCurrent;
<a name="l00059"></a>00059         <span class="keywordtype">long</span> <span class="keywordtype">int</span> i;
<a name="l00060"></a>00060         neigh_node = <a class="code" href="hashtbl_8c.html#a09a188d83a55ba59116a7c301c032a68">hashtbl_get</a>(net-&gt;<a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a>, (<span class="keyword">const</span> <span class="keywordtype">char</span> *) &amp;NodeSource);
<a name="l00061"></a>00061 
<a name="l00062"></a>00062         <span class="keywordflow">if</span> (neigh_node != NULL) {
<a name="l00063"></a>00063                 array_fromlist = calloc (<a class="code" href="list_8c.html#ac717ae40c94d5cb0fdbe46e08f2c639e">list_get_size</a>(neigh_node) + 1, <span class="keyword">sizeof</span>(<span class="keywordtype">long</span> <span class="keywordtype">int</span>));
<a name="l00064"></a>00064                 <span class="keywordflow">if</span> (array_fromlist == NULL)
<a name="l00065"></a>00065                 {
<a name="l00066"></a>00066                         exit (EXIT_FAILURE);
<a name="l00067"></a>00067                 }
<a name="l00068"></a>00068                 array_fromlist[0] = <a class="code" href="list_8c.html#ac717ae40c94d5cb0fdbe46e08f2c639e">list_get_size</a>(neigh_node);
<a name="l00069"></a>00069                 <span class="keywordflow">for</span> (i = 1; i &lt;= array_fromlist[0]; i++)
<a name="l00070"></a>00070                 {
<a name="l00071"></a>00071                         NodeCurrent = <a class="code" href="list_8c.html#a485ab244d725fddf0f2bc2e263250756">list_get_elem</a>(neigh_node, i);
<a name="l00072"></a>00072                         array_fromlist[i] = <a class="code" href="tuple_8c.html#aa348d967e695d93a7ffa0169b3baa475">tuple_fst</a>(NodeCurrent);
<a name="l00073"></a>00073             free(NodeCurrent);
<a name="l00074"></a>00074                         
<a name="l00075"></a>00075                 }
<a name="l00076"></a>00076         }
<a name="l00077"></a>00077         <span class="keywordflow">return</span> array_fromlist;
<a name="l00078"></a>00078 }
<a name="l00079"></a>00079 
<a name="l00080"></a>00080 
<a name="l00082"></a><a class="code" href="network_8h.html#aa9c38ef77dcf1df779b81eaa7f9f91ce">00082</a> <span class="keywordtype">long</span> <span class="keywordtype">int</span> <a class="code" href="network_8c.html#aa9c38ef77dcf1df779b81eaa7f9f91ce">network_get_capacity</a> (<a class="code" href="structs_network.html">Network</a> net, <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> Node_s, <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> Node_t)
<a name="l00083"></a>00083 {
<a name="l00084"></a>00084     <a class="code" href="structs_list.html">List</a> neigh_node;
<a name="l00085"></a>00085         <a class="code" href="structs_tuple.html">Tuple</a> NodeCurrent;
<a name="l00086"></a>00086         <span class="keywordtype">long</span> <span class="keywordtype">int</span> i;
<a name="l00087"></a>00087     <span class="keywordtype">long</span> <span class="keywordtype">int</span> capacity = -1; <span class="comment">/* Si no existe arista entre Node_s y Node_t */</span>
<a name="l00088"></a>00088         neigh_node = <a class="code" href="hashtbl_8c.html#a09a188d83a55ba59116a7c301c032a68">hashtbl_get</a>(net-&gt;<a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a>, (<span class="keyword">const</span> <span class="keywordtype">char</span> *) &amp;Node_s);
<a name="l00089"></a>00089     
<a name="l00090"></a>00090     <span class="keywordflow">for</span> (i = 0; i &lt;= <a class="code" href="list_8c.html#ac717ae40c94d5cb0fdbe46e08f2c639e">list_get_size</a>(neigh_node); i++) 
<a name="l00091"></a>00091     {
<a name="l00092"></a>00092         NodeCurrent = <a class="code" href="list_8c.html#a485ab244d725fddf0f2bc2e263250756">list_get_elem</a>(neigh_node, i);
<a name="l00093"></a>00093         <span class="keywordflow">if</span> (Node_t == <a class="code" href="tuple_8c.html#aa348d967e695d93a7ffa0169b3baa475">tuple_fst</a>(NodeCurrent))
<a name="l00094"></a>00094         {
<a name="l00095"></a>00095             capacity = <a class="code" href="tuple_8c.html#af79fbe5f09e6ffcc071d3990ddf3f25e">tuple_snd</a>(NodeCurrent);
<a name="l00096"></a>00096             <span class="comment">/*printf(&quot;capacity = %li, node current = %li\n&quot;, capacity, tuple_fst(NodeCurrent));*/</span>
<a name="l00097"></a>00097             <a class="code" href="tuple_8c.html#af8c1a0758eeec0c5b89e0ddd9ea7cf52">tuple_destroy</a>(NodeCurrent);
<a name="l00098"></a>00098             <span class="keywordflow">break</span>;
<a name="l00099"></a>00099         }
<a name="l00100"></a>00100        <a class="code" href="tuple_8c.html#af8c1a0758eeec0c5b89e0ddd9ea7cf52">tuple_destroy</a>(NodeCurrent);
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102     <span class="keywordflow">return</span> capacity;
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 
<a name="l00108"></a><a class="code" href="network_8h.html#addb9d5dc098787026bbcca671f115f27">00108</a> <a class="code" href="structs_network.html">Network</a> <a class="code" href="network_8c.html#addb9d5dc098787026bbcca671f115f27">network_destroy</a> (<a class="code" href="structs_network.html">Network</a> Net)
<a name="l00109"></a>00109 {
<a name="l00110"></a>00110         <a class="code" href="hashtbl_8c.html#a4c57259cd505c293809adf10fa98cd7a">hashtbl_destroy</a> (Net-&gt;<a class="code" href="structs_network.html#aa774e2143f5f7d266b7849ec7a384aac">Hash</a>);
<a name="l00111"></a>00111         free(Net);
<a name="l00112"></a>00112         <span class="keywordflow">return</span> Net;
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="network_8c.html">network.c</a>      </li>
      <li class="footer">Generado el Miércoles, 13 de Abril de 2011 20:34:14 para bfsNet por&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>Todo</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Estructuras de Datos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Archivos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Funciones</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>&apos;typedefs&apos;</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>&apos;defines&apos;</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


</body>
</html>
